Hi,
I have started out c++ with jumping into c++ and in chapter 3 there is an example readnum.cpp which i have modified to get another input as float variable as below
Code:
#include <iostream>
int main()
{
int thisisanumber;
float thisisanothernumber;
cout << "Please enter a number: ";
cin >> thisisanumber;
cout << "You have entered: " << thisisanumber << endl;
cout << "Please enter another number: ";
cin >> thisisanothernumber;
cout << "You have entered: " << thisisanothernumber << endl;
}
Now if i give a int input to first number everything works fine. But if i give a decimal input to the first variable i expected it to truncate and just show a int, but strange thing happens which is it skips the second input and directly displays me both the output
for e.g.
Please enter a number: 32.5
You have entered: 32
Please enter another number: You have entered: 0.5
What would be the cause?
Thanks a lot in advance.